package com.raymond.client.utils;

/**
 * 缓存时间
 *
 * @author :  raymond
 * @version :  V1.0
 * @date :  2021-07-14 14:24
 */
public enum CachedMillisecondClock {
    /**
     * 单例
     */
    INS;
    /**
     * 当前时间
     */
    private volatile long now = 0;

    CachedMillisecondClock() {
        this.now = System.currentTimeMillis();
        start();
    }

    private void start() {
        Thread t = new Thread(() -> {
            while (true) {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                now = System.currentTimeMillis();
            }
        },"CachedMillisecondClockUpdater");
        t.setDaemon(true);
        t.start();
    }

    public long now() {
        return now;
    }
}
